/**
 * Project Name:mauto-web
 * File Name:AreaService.java
 * Package Name:com.inftech.mauto.sys.service
 * Date:2016年10月7日下午9:14:13
 * Copyright (c) 2016, inf-technology Co., Ltd. All Rights Reserved.
 *
*/

package com.inftech.mauto.sys.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.inftech.mauto.common.constant.BusinessConstant;
import com.inftech.mauto.common.utils.CommonUtils;
import com.inftech.mauto.sys.dao.ICarDoctorDao;
import com.inftech.mauto.sys.entity.CarDoctor;
import com.mingsoft.base.biz.impl.BaseBizImpl;
import com.mingsoft.base.dao.IBaseDao;
import com.mingsoft.weixin.dao.IWeixinDao;
import com.mingsoft.weixin.entity.WeixinEntity;
import com.mingsoft.weixin.util.BaseUtils;
import com.mingsoft.weixin.util.KfSessionUtils;

/**
 * ClassName:CarDoctorService <br/>
 * Function: 车大夫业务service. <br/>
 * Date: 2016年10月7日 下午9:14:13 <br/>
 * 
 * @author puyf
 * @version
 * @since JDK 1.7
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Service("carDoctorService")
public class CarDoctorService extends BaseBizImpl {

	/**
	 * 车大夫持久化层注入
	 */
	@Autowired
	private ICarDoctorDao carDoctorDao;

	/**
	 * 注入微信持久化层
	 */
	@Autowired
	private IWeixinDao weixinDao;
	
	/**
	 * 后台服务器地址
	 */
	@Value("${adminUrl}")
	private String adminUrl;

	@Override
	protected IBaseDao getDao() {
		return carDoctorDao;
	}

	/**
	 * 
	 * queryCarDoctorList:查询车大夫列表. <br/>
	 *
	 * @author puyf
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public List<Map<String, Object>> queryCarDoctorListFront() throws Exception {
		/*// 获取微信信息
		WeixinEntity weixin = weixinDao.getEntity(null, null, null);
		KfSessionUtils kfSessionUtils = new KfSessionUtils(weixin.getWeixinAppID(), weixin.getWeixinAppSecret());
		// 获取微信方客服列表
		List<Map<String, Object>> kfList = kfSessionUtils.getKfList();*/
		// 获取数据库车大夫列表
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("objectType", BusinessConstant.FILE_TYPE_CAR_DOCTOR_IMG);
		List<CarDoctor> carDoctorList = carDoctorDao.queryCarDoctorList(paramMap);
		// 返回列表
		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		if (carDoctorList != null && carDoctorList.size() != 0) {
			for (CarDoctor carDoctor : carDoctorList) {
				Map<String, Object> carDoctorM = new HashMap<String, Object>();
				// 车大夫id
				carDoctorM.put("id", carDoctor.getId());
				// 车大夫帐号
				carDoctorM.put("cdAccount", carDoctor.getCdAccount());
				// 车大夫名称
				carDoctorM.put("cdName", carDoctor.getCdName());
				// 车大夫职称
				carDoctorM.put("cdTitle", carDoctor.getCdTitle());
				// 车大夫就职企业
				carDoctorM.put("cdEnterprise", carDoctor.getCdEnterprise());
				// 车大夫专长
				carDoctorM.put("cdSkill", carDoctor.getCdSkill());
				// 车大夫评分
				carDoctorM.put("cdScore", carDoctor.getCdScore());
				// 车大夫头像地址
				if (!CommonUtils.isBlank(carDoctor.getCdImg())) {
					carDoctorM.put("cdImg", adminUrl + carDoctor.getCdImg());
				}
				/*for (Map<String, Object> kfMap : kfList) {
					if (carDoctor.getCdAccount().equals(kfMap.get(BaseUtils.KF_ACCOUNT))) {
						// 车大夫状态
						carDoctorM.put("cdStatus", Integer.valueOf(kfMap.get(BaseUtils.KF_STATUS).toString()));
						// 车大夫头像地址
						// carDoctorM.put("cdHeadimgurl",
						// kfMap.get(BaseUtils.KF_HEADIMGURL).toString());
						break;
					}
				}*/
				resultList.add(carDoctorM);
			}
		}
		return resultList;
	}

	/**
	 * 
	 * queryCarDoctorList:后台查询车大夫列表. <br/>
	 * 
	 * @author puyf
	 * @param paramMap
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public List<CarDoctor> queryCarDoctorList(Map<String, Object> paramMap) throws Exception {
		// 获取服务单位列表
		paramMap.put("objectType", BusinessConstant.FILE_TYPE_CAR_DOCTOR_IMG);
		List<CarDoctor> carDoctorList = carDoctorDao.queryCarDoctorList(paramMap);
		return carDoctorList;
	}

	/**
	 * 
	 * queryCarDoctor:查询车大夫实体. <br/>
	 *
	 * @author puyf
	 * @param id
	 * @return
	 * @throws Exception
	 * @since JDK 1.7
	 */
	public Map<String, Object> queryCarDoctor(int id) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("id", id);
		paramMap.put("objectType", BusinessConstant.FILE_TYPE_CAR_DOCTOR_IMG);
		// 获取车大夫实体
		CarDoctor carDoctor = carDoctorDao.queryCarDoctor(paramMap);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 返回对象
		if (carDoctor != null) {
			// 车大夫帐号
			resultMap.put("cdAccount", carDoctor.getCdAccount());
			// 车大夫名称
			resultMap.put("cdName", carDoctor.getCdName());
			// 车大夫职称
			resultMap.put("cdTitle", carDoctor.getCdTitle());
			// 车大夫就职企业
			resultMap.put("cdEnterprise", carDoctor.getCdEnterprise());
			// 车大夫专长
			resultMap.put("cdSkill", carDoctor.getCdSkill());
			// 车大夫评分
			resultMap.put("cdScore", carDoctor.getCdScore());
			// 车大夫头像地址
			if (!CommonUtils.isBlank(carDoctor.getCdImg())) {
				resultMap.put("cdImg", adminUrl + carDoctor.getCdImg());
			}
		}
		return resultMap;
	}
}
